package simpleGeom;

import processing.core.PGraphics;

public class Edge3D implements HasLine2D,HasBounds3D{
public HasPos3D p1;
public HasPos3D p2;
public Edge3D(HasPos3D p1,HasPos3D p2){
	this.p1=p1;
	this.p2=p2;
}
public Edge3D(){
	
}
public float getX1(){
	return p1.getX();
}
public float getY1(){
	return p1.getY();
}
public float getZ1(){
	return p1.getZ();
}
public float getX2(){
	return p2.getX();
}
public float getY2(){
	return p2.getY();
}

public float getZ2(){
	return p2.getZ();
}
public Vec3D getVector(){
	return Vec3D.sub(p2, p1);
}

public Vec3D getCenter(){
	Vec3D c=Vec3D.add(p1, p2);
	c.mult(0.5f);
	return c;
}
public float getAngle(){
	Vec2D v=getVector();
	return v.getAngle();
}
public float getLength(){
	return Vec3D.dist(p1, p2);
}
public int  getNSegmentsMinLength(float minL){
	int n=(int)(getLength()/minL);
	return Math.max(1,n);
}
public Vec3D[] getSegments(int n){
	Vec3D[] segments=new Vec3D[n+1];
	Vec3D v=getVector();
	v.div(n);
	for (int i=0;i<n+1;i++){
		Vec3D p=Vec3D.mult(v, i);
		p.add(p1);
		segments[i]=p;
	}
	return segments;
}
public Vec3D getPointAbs(float dist){
	Vec3D v=getVector();
	v.setLength(dist);
	v.add(p1);
	return v;
}
public HasPos3D getP1() {
	return p1;
}
public void setP1(HasPos3D p1) {
	this.p1 = p1;
}
public HasPos3D getP2() {
	return p2;
}
public void setP2(HasPos3D p2) {
	this.p2 = p2;
}
public Vec3D getPoint(float fac){
	float cX=getX2()-getX1()+getX1();
	float cY=getY2()-getY1()+getY1();
	float cZ=getZ2()-getZ1()+getZ1();
	return new Vec3D(cX,cY,cZ);
}
public  Edge3D getOffsetEdge(
		float offset) {
	Vec2D v=Vec2D.sub(getP2(), getP1());
	v.setLength(offset);
	v.rot90m();
	Vec2D p1Offset = Vec2D.add(p1, v);
	Vec2D p2Offset = Vec2D.add(p2, v);
	return new Edge3D(new Vec3D(p1Offset), new Vec3D(p2Offset));
}
public void display3D(PGraphics g) {
	// TODO Auto-generated method stub
	g.line(getX1(), getY1(),getZ1(), getX2(), getY2(),getZ2());
}
public void display2D(PGraphics g) {
	// TODO Auto-generated method stub
	g.line(getX1(), getY1(), getX2(), getY2());
}
@Override
public Box3D getBounds3D() {
	// TODO Auto-generated method stub
	Bounds3D b=new Bounds3D();
	b.addPoint(getX1(),getY1(),getZ1());
	b.addPoint(getX2(),getY2(),getZ2());
	return b;
}
}
